package cn.itcast.model.util

import cn.itcast.model.bean.HBaseMeta
import org.apache.spark.sql.{DataFrame, SQLContext, SaveMode}
import org.apache.spark.sql.sources.{BaseRelation, CreatableRelationProvider, RelationProvider}

class HbaseSource extends CreatableRelationProvider with RelationProvider with Serializable {
  override def createRelation(sqlContext: SQLContext, mode: SaveMode, parameters: Map[String, String], data: DataFrame): BaseRelation = {
    val relation = new HBaseWritableRelation(sqlContext,HBaseMeta(parameters),data)
    relation.insert(data,false)
    relation
  }
  override def createRelation(sqlContext: SQLContext,
                              parameters: Map[String, String]): BaseRelation = {

    new HBaseReadableRelation(sqlContext, HBaseMeta(parameters))
  }
}
